<template>
  <div>
    <router-view/>
    <!-- 为了每次点击刷新数据 -->
    <!-- <router-view v-slot="{ Component }">
      <transition>
        <keep-alive>
          <component :is="Component" />
        </keep-alive>
      </transition>  
    </router-view> -->
    <div id="nav">
      <router-link to="/" class="tab-bar-item">
        <div class="icon"><i class="iconfont icon-home"></i></div>
        <div>首页</div>
      </router-link>
      <router-link to="/category" class="tab-bar-item">
      <div class="icon"><i class="iconfont icon-fenlei"></i></div>
        <div>分类</div>
      </router-link>
      <router-link to="/shopcart" class="tab-bar-item">
        <div class="icon">
          <!-- 徽章  在购物车的图标上显示消息数量 -->
          <van-badge :content="$store.state.cartCount" max="9">
              <i class="iconfont icon-gouwuche"></i>
          </van-badge>
        </div>
        <div>购物车</div>
      </router-link>
      <router-link to="/profile" class="tab-bar-item">
        <div  class="icon" ><i class="iconfont icon-yonghu"></i></div>
        <div>我的</div>
      </router-link> 
    </div>
  </div>
</template>
<script>
import {onMounted} from 'vue'
import {useStore} from 'vuex'
export default {
  setup(){
    // 获取对象
    const store = useStore();
    // 状态管理
    onMounted(()=>{
      store.dispatch('updateCart');
    })
  }
}
</script>
<style lang="scss">
@import 'assets/css/base.css';
@import 'assets/css/iconfont.css';
#app {
  font-family: Avenir, Helvetica, Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  text-align: center;
  color: #2c3e50;
}

#nav {
  background-color: #F6F6F6;
  width: 100%;
  display: flex;
  // 将导航栏定位于底部
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  box-shadow: 0 -3px 1px rgba(100,100,100,0.1);
  z-index: 25;
  a {
    color: var(--color-text);

    &.router-link-exact-active {
      // color: #42b983;
      color: var(--color-high-text);
    }
  }
  // 每个导航的类
  .tab-bar-item{
    flex: 1;
    text-align: center;
    height: 50px;
    font-size: var(--font-size);
  }
  // 图标
  .tab-bar-item .icon{
    width: 24px;
    height: 24px;
    margin-top: 4px;
    vertical-align: middle;
    display: inline-block;
  }
}
// 导航

</style>
